package com.fr.report.parameter.processor;

import com.fr.base.Inter;
import com.fr.base.StringUtils;
import com.fr.base.XMLable;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.parameter.Parameter;

public class SQLQueryCondition
  implements XMLable
{
  private String append;
  private String left;
  private String operator;
  private Object right;
  private String like_start;
  private String like_end;

  public SQLQueryCondition()
  {
    this(null, "", "=", new Parameter(Inter.getLocText("Parameter")));
  }

  public SQLQueryCondition(String paramString1, String paramString2, Object paramObject)
  {
    this(null, paramString1, paramString2, paramObject);
  }

  public SQLQueryCondition(String paramString1, String paramString2, String paramString3, Object paramObject)
  {
    this.like_start = null;
    this.like_end = null;
    this.left = paramString2;
    this.right = paramObject;
    this.append = paramString1;
    this.operator = paramString3;
  }

  public String getAppend()
  {
    return this.append;
  }

  public void setAppend(String paramString)
  {
    this.append = paramString;
  }

  public String getLeft()
  {
    return this.left;
  }

  public void setLeft(String paramString)
  {
    this.left = paramString;
  }

  public Object getRight()
  {
    return this.right;
  }

  public void setRight(Object paramObject)
  {
    this.right = paramObject;
  }

  public String getOperator()
  {
    return this.operator;
  }

  public void setOperator(String paramString)
  {
    this.operator = paramString;
  }

  public void setLikeStart(String paramString)
  {
    this.like_start = paramString;
  }

  public String getLikeStart()
  {
    return this.like_start;
  }

  public void setLikeEnd(String paramString)
  {
    this.like_end = paramString;
  }

  public String getLikeEnd()
  {
    return this.like_end;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
    {
      String str1;
      if ((str1 = paramXMLableReader.getAttr("append")) != null)
        setAppend(str1);
      if ((str1 = paramXMLableReader.getAttr("left")) != null)
        setLeft(str1);
      if ((str1 = paramXMLableReader.getAttr("op")) != null)
        setOperator(str1);
      if ((str1 = paramXMLableReader.getAttr("like_start")) != null)
        setLikeStart(str1);
      if ((str1 = paramXMLableReader.getAttr("like_end")) != null)
        setLikeEnd(str1);
    }
    if (paramXMLableReader.isChildNode())
    {
      String str2 = paramXMLableReader.getTagName();
      if (("Object".equals(str2)) || ("O".equals(str2)))
        setRight(ReportXMLUtils.readObject(paramXMLableReader));
      else if ("Parameter".equals(str2))
        setRight(ReportXMLUtils.readParameter(paramXMLableReader));
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("SQLQueryCondition");
    if (this.append != null)
      paramXMLPrintWriter.attr("append", getAppend());
    if (this.left != null)
      paramXMLPrintWriter.attr("left", getLeft());
    if (this.operator != null)
      paramXMLPrintWriter.attr("op", getOperator());
    if (!(StringUtils.isBlank(this.like_start)))
      paramXMLPrintWriter.attr("like_start", getLikeStart());
    if (!(StringUtils.isBlank(this.like_end)))
      paramXMLPrintWriter.attr("like_end", getLikeEnd());
    ReportXMLUtils.writeObject(paramXMLPrintWriter, getRight());
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }

  public String toString()
  {
    if ((this.operator.equals("EXISTS")) || (this.operator.equals("NOT EXISTS")))
      return ((this.append != null) ? this.append + " " : "") + this.operator + " " + this.right;
    if ((((this.operator.equals("LIKE")) || (this.operator.equals("NOT LIKE")))) && (((!(StringUtils.isBlank(this.like_start))) || (!(StringUtils.isBlank(this.like_end))))))
      return ((this.append != null) ? this.append + " " : "") + this.left + " " + this.operator + " '" + ((this.like_start == null) ? "" : this.like_start) + this.right + ((this.like_end == null) ? "" : this.like_end) + "'";
    return ((this.append != null) ? this.append + " " : "") + this.left + " " + this.operator + " " + this.right;
  }
}